class AcGameMenu {
    //传Acgame对象
    constructor (root) {
        this.root=root
        this.$menu = $(`
<div class="ac-game-menu">
    <div class="ac-game-menu-field">
        <div class="ac-game-menu-field-item ac-game-menu-field-item-single">
            单人模式
        </div>
        <div class="ac-game-menu-field-item ac-game-menu-field-item-multi">
            多人模式
        </div>
        <div class="ac-game-menu-field-item ac-game-menu-field-item-settings">
            设置
        </div>
    </div>
</div>
            `);
        this.$menu.hide();
        this.root.$ac_game.append(this.$menu);
        this.$single_mode = this.$menu.find('.ac-game-menu-field-item-single'); //class加.,id加#
        this.$multi_mode = this.$menu.find('.ac-game-menu-field-item-multi');//find找到calss的对应名字
        this.$settings = this.$menu.find('.ac-game-menu-field-item-settings'); //class加.,id加#
        this.start()
    }

    start() {
        this.add_listening_events();
    }

    add_listening_events(){
        var that = this;
        this.$single_mode.click(function(){
            that.hide();
            that.root.playground.show("single mode")
        });
        this.$multi_mode.click(function(){
            if(that.$multi_mode.text() !== "退出登录"){
                that.hide();
                that.root.playground.show("multi mode")
            }else{
                that.root.settings.logout_on_remote();
                location.reload();
            }
        });
        this.$settings.click(function(){

            if(that.$settings.text()==="返回"){
                that.$multi_mode.html("多人模式")
                that.$settings.html("设置");
            }else {
                that.$settings.html("返回");
                that.$multi_mode.html("退出登录")
            }
        });
    }

    show(){ //显示当前页面
        this.$menu.show();
    }

    hide(){ //隐藏页面
        this.$menu.hide();
    }
}
